package me.zhengjie.modules.system.service.apply;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 王宇
 */
@Component
public class ApplyWorkOrderFactory implements ApplicationContextAware {

    private static final Map<Integer, IApplyCallbackService> CALLBACK_MAP = new HashMap<>();

    public IApplyCallbackService getApplyType(Integer applyType) {
        return CALLBACK_MAP.get(applyType);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, IApplyCallbackService> beans = applicationContext.getBeansOfType(IApplyCallbackService.class);
        beans.values().forEach(bean -> CALLBACK_MAP.put(bean.getApplyType(), bean));
    }
}
